package com.atguigu.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.atguigu.base.BaseController;
import com.atguigu.entity.HouseUser;
import com.atguigu.service.HouseUserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author 杨林
 * @create 2022-09-20 15:07 星期二
 * description:
 */
@Controller
@RequestMapping("/houseUser")
public class HouseUserController extends BaseController {

    @Reference
    private HouseUserService houseUserService;

    @RequestMapping("/create")
    public String crate(Long houseId, Model model){
        model.addAttribute("houseId",houseId);
        return "houseUser/create";
    }


    @RequestMapping("/save")
    private String insert(HouseUser houseUser){
        System.out.println(houseUser);
        houseUserService.insert(houseUser);
        return "common/successPage";
    }

    @RequestMapping("/delete/{houseId}/{id}")
    public String delete(@PathVariable Long houseId,@PathVariable Long id){
        houseUserService.delete(id);
        return "redirect:/house/" + houseId;
    }


    @RequestMapping("edit/{id}")
    public String edit(@PathVariable Long id,Model model){
        //根据id获取房东信息
        HouseUser houseUser = houseUserService.getById(id);
        model.addAttribute("houseUser",houseUser);
        return "houseUser/edit";
    }

    @RequestMapping("/update")
    public String update(HouseUser houseUser){
        houseUserService.update(houseUser);
        return "common/successPage";
    }
}
